package cn.cdutetc.library.entity.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付状态枚举
 */
@Getter
@AllArgsConstructor
public enum PaymentStatusEnum {

    PENDING(1, "待支付"),
    PAID(2, "已支付"),
    CANCELLED(3, "已取消");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     * @param code 状态码
     * @return 枚举
     */
    public static PaymentStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (PaymentStatusEnum status : PaymentStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
